﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using GqqMvcWeb.Models.Database;

namespace GqqMvcWeb.Services
{
    /// <summary>
    /// 可以通过这种方法来建表，但是：
    /// Model compatibility cannot be checked because the database does not contain 
    /// model metadata. Model compatibility can only be checked for databases created 
    /// using Code First or Code First Migrations.
    /// </summary>
    public class SchoolInitializer : DropCreateDatabaseIfModelChanges<SchoolContext>
    {
        protected override void Seed(SchoolContext context)
        {

            var students = new List<student>
                               {
                                   new student {FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01")},
                                   new student {FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01")},
                                   new student {FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01")},
                                   new student {FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01")},
                                   new student {FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2002-09-01")},
                                   new student {FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2001-09-01")},
                                   new student {FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2003-09-01")},
                                   new student {FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01")}
                               };
            students.ForEach(s => context.Students.Add(s));
            context.SaveChanges();
//
//            var instructors = new List<instructor>
//                                  {
//                                      new instructor {FirstMidName = "Kim", LastName = "Abercrombie", HireDate = DateTime.Parse("1995-03-11")},
//                                      new instructor {FirstMidName = "Fadi", LastName = "Fakhouri", HireDate = DateTime.Parse("2002-07-06")},
//                                      new instructor {FirstMidName = "Roger", LastName = "Harui", HireDate = DateTime.Parse("1998-07-01")},
//                                      new instructor {FirstMidName = "Candace", LastName = "Kapoor", HireDate = DateTime.Parse("2001-01-15")},
//                                      new instructor {FirstMidName = "Roger", LastName = "Zheng", HireDate = DateTime.Parse("2004-02-12")}
//                                  };
//            instructors.ForEach(s => context.Instructors.Add(s));
//            context.SaveChanges();
//
//            var departments = new List<department>
//                                  {
//                                      new department {Name = "English", Budget = 350000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = 1},
//                                      new department {Name = "Mathematics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = 2},
//                                      new department {Name = "Engineering", Budget = 350000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = 3},
//                                      new department {Name = "Economics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = 4}
//                                  };
//            departments.ForEach(s => context.Departments.Add(s));
//            context.SaveChanges();
//
//            var courses = new List<course>
//                              {
//                                  new course {CourseID = 1050, Title = "Chemistry", Credits = 3, DepartmentID = 3, Instructors = new List<instructor>()},
//                                  new course {CourseID = 4022, Title = "Microeconomics", Credits = 3, DepartmentID = 4, Instructors = new List<instructor>()},
//                                  new course {CourseID = 4041, Title = "Macroeconomics", Credits = 3, DepartmentID = 4, Instructors = new List<instructor>()},
//                                  new course {CourseID = 1045, Title = "Calculus", Credits = 4, DepartmentID = 2, Instructors = new List<instructor>()},
//                                  new course {CourseID = 3141, Title = "Trigonometry", Credits = 4, DepartmentID = 2, Instructors = new List<instructor>()},
//                                  new course {CourseID = 2021, Title = "Composition", Credits = 3, DepartmentID = 1, Instructors = new List<instructor>()},
//                                  new course {CourseID = 2042, Title = "Literature", Credits = 4, DepartmentID = 1, Instructors = new List<instructor>()}
//                              };
//            courses.ForEach(s => context.Courses.Add(s));
//            context.SaveChanges();
//
//            courses[0].Instructors.Add(instructors[0]);
//            courses[0].Instructors.Add(instructors[1]);
//            courses[1].Instructors.Add(instructors[2]);
//            courses[2].Instructors.Add(instructors[2]);
//            courses[3].Instructors.Add(instructors[3]);
//            courses[4].Instructors.Add(instructors[3]);
//            courses[5].Instructors.Add(instructors[3]);
//            courses[6].Instructors.Add(instructors[3]);
//            context.SaveChanges();
//
//            var enrollments = new List<enrollment>
//                                  {
//                                      new enrollment {StudentID = 1, CourseID = 1050, Grade = 1},
//                                      new enrollment {StudentID = 1, CourseID = 4022, Grade = 3},
//                                      new enrollment {StudentID = 1, CourseID = 4041, Grade = 1},
//                                      new enrollment {StudentID = 2, CourseID = 1045, Grade = 2},
//                                      new enrollment {StudentID = 2, CourseID = 3141, Grade = 4},
//                                      new enrollment {StudentID = 2, CourseID = 2021, Grade = 4},
//                                      new enrollment {StudentID = 3, CourseID = 1050},
//                                      new enrollment {StudentID = 4, CourseID = 1050,},
//                                      new enrollment {StudentID = 4, CourseID = 4022, Grade = 4},
//                                      new enrollment {StudentID = 5, CourseID = 4041, Grade = 3},
//                                      new enrollment {StudentID = 6, CourseID = 1045},
//                                      new enrollment {StudentID = 7, CourseID = 3141, Grade = 2},
//                                  };
//            enrollments.ForEach(s => context.Enrollments.Add(s));
//            context.SaveChanges();
//
//            var officeAssignments = new List<officeAssignment>
//                                        {
//                                            new officeAssignment {InstructorID = 1, Location = "Smith 17"},
//                                            new officeAssignment {InstructorID = 2, Location = "Gowan 27"},
//                                            new officeAssignment {InstructorID = 3, Location = "Thompson 304"},
//                                        };
//            officeAssignments.ForEach(s => context.OfficeAssignments.Add(s));
//            context.SaveChanges();
        }
    }

}